package com.company.堆栈队列;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author zhangjian
 * @data 2023/2/17
 * @Version 1.0
 */
public class 最大嵌套括号数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        int number = getmaxNumber(str);
        System.out.println(number);
    }

    private static int getmaxNumber(String str) {
        Stack<Character> stack = new Stack<>();
        int max = 0;
        int count = 0;
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '(') {
                stack.push(')');
                continue;
            } else if (chars[i] == '{') {
                stack.push('}');
                continue;
            } else if (chars[i] == '[') {
                stack.push(']');
                continue;
            } else if (stack.isEmpty() || stack.peek() != chars[i]) {
                return 0;
            } else if (stack.peek() == chars[i]) {
                max = Math.max(max, stack.size());
                stack.pop();
            }
        }
        return max;
    }


}


